#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e5+10;
const int M = 1e6+10;
const int L = 78499;
const int mod = 1e9+7;

int pnum,prime[M],cnt[L],l,r,n,a[N],m,BL,id[M];
ll s1[L][25],s2[L][25];
bool v[M],app[M];
vector<pii> ft[M];
ll tot1 = 1,tot2 = 1,ans[N];

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1)res=res*x%mod;return res;}

void init(int lim){
	int pp = 0;
	for(int i = 2;i <= lim;i++){
		if(!v[i]) prime[++pnum] = i,id[i] = pnum;if(i > L) pp = pnum;
		for(int j = 1;j <= pnum && i * prime[j] <= lim;j++){
			v[i * prime[j]] = 1; if(i % prime[j] == 0) break;
		}
	}if(!pp) pp = pnum;
	for(int i = 2;i <= lim;i++){
		if(!app[i]) continue;
		if(!v[i]) {ft[i].pb(pii(id[i],1));continue;}
		int x = i;
		for(int j = 1;j <= pp && prime[j] * prime[j] <= x;j++){
			pii t = pii(j,0);
			while(x % prime[j] == 0){
				x /= prime[j];
				t.se++;
			}ft[i].pb(t);
		}
		if(x > 1) ft[i].pb(pii(id[x],1));
	}
	for(int i = 1;i <= pp;i++){
		int x = prime[i];
		s1[i][0] = 1; for(int j = 1;j < 25 && x * s1[i][j-1] <= lim;j++) s1[i][j] = s1[i][j-1] * x;
		s2[i][0] = 1; s2[i][1] = prime[i] - 1; for(int j = 2;j < 25 && x * s2[i][j-1] <= lim;j++) s2[i][j] = s2[i][j-1] * x;
	}for(int i = pp + 1;i <= pnum;i++){
		s1[i][1] = s2[i][1] = prime[i] - 1;
	}
}

void add(int x){
	for(pii f : ft[x]){
		if(cnt[f.fi] == 0) cnt[f.fi] += f.se,tot1 = tot1 * s2[f.fi][f.se] % mod;
		else cnt[f.fi] += f.se,tot1 = tot1 * s1[f.fi][f.se] % mod;
	}
}

void del(int x){
	for(pii f : ft[x]){
		if(cnt[f.fi] == f.se) cnt[f.fi] -= f.se,tot2 = tot2 * s2[f.fi][f.se] % mod;
		else cnt[f.fi] -= f.se,tot2 = tot2 * s1[f.fi][f.se] % mod;
	}
}

struct query{
	int id,l,r,bl;
	bool operator < (const query b)const{return bl ^ b.bl ? bl < b.bl : bl & 1 ? r < b.r : r > b.r;}
}q[N];
	
int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;int mx = 0;
	for(int i = 1;i <= n;i++) a[i] = in,mx = max(mx,a[i]),app[a[i]] = 1;
	init(mx);
	m = in; BL = 1220;
	for(int i = 1;i <= m;i++){
		q[i].l = in;q[i].r = in; q[i].bl = (q[i].l - 1) / BL + 1; q[i].id = i;
	}
	sort(q+1,q+m+1);int l = 1,r = 0;
	for(int i = 1;i <= m;i++){
		while(r < q[i].r) add(a[++r]);
		while(r > q[i].r) del(a[r--]);
		while(l < q[i].l) del(a[l++]);
		while(l > q[i].l) add(a[--l]);
		ans[q[i].id] = tot1 * qp(tot2,mod-2) % mod;
	}
	for(int i = 1;i <= m;i++) printf("%lld\n",ans[i]);
	return 0;
}

